package com.haiheng.module_main.adapter.bookcar

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.haiheng.library_base.adapter.BaseAdapter
import com.haiheng.library_base.db.BookInfoBean
import com.haiheng.module_main.R
import com.haiheng.module_main.bean.res.bookcar.BookCarBookResult
import com.haiheng.module_main.databinding.ItemBookCarBinding
import com.haiheng.module_main.databinding.ItemBookListBinding

/**
 *
 * @Des:
 * @Author: hwz
 * @Date:2024/8/21 0021
 * @Version: 1.0
 */
class BookCarAdapter(
    private val onBookSelected: (BookCarBookResult) -> Unit
) : BaseAdapter<BookCarBookResult>() {

    override fun onCreateViewBinding(viewType: Int): (LayoutInflater, ViewGroup, Boolean) -> ViewBinding {
        return ItemBookCarBinding::inflate
    }

    override fun onItemView(holder: ViewBindHolder, position: Int, item: BookCarBookResult) {
        val binding = holder.binding as ItemBookCarBinding

        binding.tvBookname.text = item.title
        binding.tvBarcode.text = item.barcode
        binding.tvBooknum.text = "${item.callNumber ?: ""}"
        binding.cbSelect.isChecked = item.isSelect
        binding.cbSelect.setOnCheckedChangeListener { _, isChecked ->
            item.isSelect = isChecked
            onBookSelected(item)
        }

    }

}
